﻿package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	
	
	public class GameBall extends MovieClip {
		
		private var time:Number = 0;
		private var mc:MovieClip;
		private var myBoxs:MovieClip = new myBox();
		private var score:int = 0;
		private var flie:DropShadowFilter = new DropShadowFilter();
		
		
		public function GameBall() {
			
			stage.addEventListener(Event.ENTER_FRAME , onLoop);
			stage.addChild(myBoxs);
			myBoxs.mouseEnabled = false;
			myBoxs.y = 600;
			//myBoxs.startDrag(true);
			flie.distance = 5;
			flie.blurX =  flie.blurY = .5;
			flie.distance = 0;
			myBoxs.filters = [flie];
			
		}
		private function onLoop(e:Event):void{
			time++;
			if(time >= 15){
				mc = new myBall();
				stage.addChild(mc);
				mc.x = Math.random() * 500;
				mc.y = 0;
				mc.speed = Math.random() * 10 + 5;
				mc.displayOBJ = mc;
				mc.addEventListener(Event.ENTER_FRAME , onEnter);
				txtScore.text = "Score : " + score.toString();
				
				time = 0;
			}
			if(score <= 0){
					score = 0;
			}
				myBoxs.x = mouseX;
		}
		private function onEnter(e:Event):void{
			e.target.y += e.target.speed;
			if(e.target.y > 650){
				stage.removeChild(e.target.displayOBJ);
				e.target.removeEventListener(Event.ENTER_FRAME , onEnter);
				score -= 2;
			}
			if(e.target.hitTestObject(myBoxs.bar)){
				score++;
				myBoxs.gotoAndPlay(1);
				stage.removeChild(e.target.displayOBJ);
				e.target.removeEventListener(Event.ENTER_FRAME , onEnter);
			}
		}
	}
	
}
